<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-10-18
 * Time: 15:40
 */

namespace app\web\controller;

use app\src\jsqdb\logic\DevListLogic;
use app\src\post\logic\PostLogic;
use app\src\post\model\Post;
use think\Controller;

/**
 *
 * Web作为webview统一入口
 *
 * @author hebidu <email:346551990@qq.com>
 *
 * @package app\web\controller
 */
class Web extends Controller
{
    /**
     * app分享，打开的链接地址
     * @return mixed
     */
    public function app_share(){
        return $this->fetch();
    }

//    public function test(){
//        $logic = new DevListLogic();
//        $logic->generate("0",50,"D00100001");
//    }

    /**
     * 用户手册
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function user_manual(){
        $this->getPost(Post::USER_MANUAL);
        return $this->fetch("post_detail");
    }


    /**
     * 关于我们
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function about(){

        $this->getPost(Post::ABOUT_US);
        return $this->fetch("post_detail");
    }

    /**
     * 联系我们
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function contact_us(){

        $this->getPost(Post::CONTACT_US);
        return $this->fetch("post_detail");
    }

    /**
     * 版权信息
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function copyright(){
        $this->getPost(Post::COPYRIGHT);
        return $this->fetch("post_detail");
    }

    /**
     * 使用协议
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function agreement(){
        $this->getPost(Post::AGREEMENT);
        return $this->fetch("post_detail");
    }

    /**
     * 购买须知
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function Purchase_notice(){
        $this->getPost(Post::Purchase_notice);
        return $this->fetch("post_detail");
    }

    /**
     * 服务条款
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function Service_provision(){
        $this->getPost(Post::Service_provision);
        return $this->fetch();
    }

    /**
     * 系统通知
     * @author hebidu <email:346551990@qq.com>
     * @return mixed
     */
    public function system_notice(){
        if(!empty(input('param.id'))){
            $map = [
                'id'          => input('param.id'),
                'post_category'=>Post::SYSTEM_NOTICE,
            ];
            $result = (new PostLogic())->queryNoPaging($map);
            $list = $result['info'];

            foreach ($list as &$vo){
                $vo = $vo->toArray();
            }

            $this->assign("list",$list);

            return $this->fetch('notice_detail');
        }else{
            $map = [
                'post_category'=>Post::SYSTEM_NOTICE,
            ];
        }
        $result = (new PostLogic())->queryNoPaging($map);
        $list = $result['info'];

        foreach ($list as &$vo){
            $vo = $vo->toArray();
        }

        $this->assign("list",$list);

        return $this->fetch();
    }

    private function getPost($category){
        $map = [
            'post_category'=>$category,
            'post_status'=>'publish',
        ];
        $result = (new PostLogic())->getInfo($map,"post_modified desc");
        $this->assign("info",$result['info']);

    }

}